package com.ruoyi.printer.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.printer.domain.PrinterFile;
import com.ruoyi.printer.service.IPrinterFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 文件管理Controller
 * 
 * @author yanyi
 * @date 2023-07-14
 */
@RestController
@RequestMapping("/printer/file")
public class PrinterFileController extends BaseController
{
    @Autowired
    private IPrinterFileService printerFileService;

    /**
     * 查询文件管理列表
     */
    @PreAuthorize("@ss.hasPermi('printer:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(PrinterFile printerFile)
    {
        startPage();
        List<PrinterFile> list = printerFileService.selectPrinterFileList(printerFile);
        return getDataTable(list);
    }

    /**
     * 导出文件管理列表
     */
    @PreAuthorize("@ss.hasPermi('printer:file:export')")
    @Log(title = "文件管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PrinterFile printerFile)
    {
        List<PrinterFile> list = printerFileService.selectPrinterFileList(printerFile);
        ExcelUtil<PrinterFile> util = new ExcelUtil<PrinterFile>(PrinterFile.class);
        util.exportExcel(response, list, "文件管理数据");
    }

    /**
     * 获取文件管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('printer:file:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") String fileId)
    {
        return success(printerFileService.selectPrinterFileByFileId(fileId));
    }

    /**
     * 新增文件管理
     */
    @PreAuthorize("@ss.hasPermi('printer:file:add')")
    @Log(title = "文件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrinterFile printerFile)
    {
        return toAjax(printerFileService.insertPrinterFile(printerFile));
    }

    /**
     * 修改文件管理
     */
    @PreAuthorize("@ss.hasPermi('printer:file:edit')")
    @Log(title = "文件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrinterFile printerFile)
    {
        return toAjax(printerFileService.updatePrinterFile(printerFile));
    }

    /**
     * 删除文件管理
     */
    @PreAuthorize("@ss.hasPermi('printer:file:remove')")
    @Log(title = "文件管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable String[] fileIds)
    {
        return toAjax(printerFileService.deletePrinterFileByFileIds(fileIds));
    }
}
